/// Creator:      fengliang
/// CreatDate:    2022-06-14
/// Description:  血袋变更明细记录
Class Nur.MNISV3.BloodBagSubRec Extends %Persistent
{

Relationship RecPref As Nur.MNISV3.BloodBagRec [ Cardinality = parent, Inverse = ChildRec ];

/// 记录日期
Property RecDate As %Library.Date(FORMAT = 1) [ InitialExpression = {+$p($h,",",1)}, Required ];

/// 记录时间
Property RecTime As %Library.Time [ InitialExpression = {+$p($h,",",2)}, Required ];

/// 记录人
Property RecUser As %Library.String(TRUNCATE = 1);

/// 核对日期
Property AuditDate As %Library.Date(FORMAT = 1);

/// 核对时间
Property AuditTime As %Library.Time;

/// 核对人
Property AuditUser As %Library.String(TRUNCATE = 1);

/// 状态
Property Status As %Library.String(TRUNCATE = 1);

/// 就诊号
Property EpisodeId As %Library.String(TRUNCATE = 1);

/// 登记号
Property PatRegNo As %Library.String(TRUNCATE = 1);

/// 科室Id
Property LocId As %Library.String(TRUNCATE = 1);

/// 汇总单条码(取血单号)
Property GetBarCode As %Library.String(TRUNCATE = 1);

/// 更新日期
Property UpdateDate As %Library.Date(FORMAT = 1);

/// 更新时间
Property UpdateTime As %Library.Time;

/// 更新人
Property UpdateUser As %Library.String(TRUNCATE = 1);

/// 对应 item1~15的类型
Property ItemType As %Library.String(TRUNCATE = 1);

Property Item1 As %Library.String(TRUNCATE = 1);

Property Item2 As %Library.String(TRUNCATE = 1);

Property Item3 As %Library.String(TRUNCATE = 1);

Property Item4 As %Library.String(TRUNCATE = 1);

Property Item5 As %Library.String(TRUNCATE = 1);

Property Item6 As %Library.String(TRUNCATE = 1);

Property Item7 As %Library.String(TRUNCATE = 1);

Property Item8 As %Library.String(TRUNCATE = 1);

Property Item9 As %Library.String(TRUNCATE = 1);

Property Item10 As %Library.String(TRUNCATE = 1);

Property Item11 As %Library.String(TRUNCATE = 1);

Property Item12 As %Library.String(TRUNCATE = 1);

Property Item13 As %Library.String(TRUNCATE = 1);

Property Item14 As %Library.String(TRUNCATE = 1);

Property Item15 As %Library.String(TRUNCATE = 1);

Property Item16 As %Library.String(TRUNCATE = 1);

Property Item17 As %Library.String(TRUNCATE = 1);

Property Item18 As %Library.String(TRUNCATE = 1);

Property Item19 As %Library.String(TRUNCATE = 1);

Property Item20 As %Library.String(TRUNCATE = 1);

Index DateTime On (RecDate, RecTime);

Index Adm On EpisodeId;

Index RegNo On PatRegNo;

Index UserDr On (RecDate, RecUser);

Index LocDate On (RecDate, LocId);

Index GetBarCode On GetBarCode;

/// Creator:      fengliang
/// CreatDate:    2022-06-14
/// Description:  保存
/// other:        w ##class(Nur.MNISV3.BloodBagSubRec).Save()
ClassMethod Save(parr As %String, id As %String, userId As %String, locId As %String, parrJson = "")
{
    s ^GRS("BloodRegSave")=$lb(parr,id,userId,locId,parrJson)
    s tmp=""
    s curDate=+$h
    s curTime=$P($H,",",2)
    d ##class(web.DHCMGNurComm).setmoudtmp(parr,.tmp)
    if id'=""
    {
        s a=##class(Nur.MNISV3.BloodBagSubRec).%OpenId(id)
    }else{
        s a=##class(Nur.MNISV3.BloodBagSubRec).%New()
    }
    b
    s a.RecPref=##class(Nur.MNISV3.BloodBagRec).%OpenId(tmp("RecPref"))
    i id="" s a.RecDate=curDate
    i id="" s a.RecTime=curTime
    i id="" s a.RecUser=userId
    s a.UpdateDate=curDate
    s a.UpdateTime=curTime
    s a.UpdateUser=userId
    i id="" s a.LocId=locId //科室字段不允许修改
    i $D(tmp("EpisodeId"))
    {
        i id="" s a.EpisodeId=tmp("EpisodeId")
        s paitentId=$p(^PAADM(tmp("EpisodeId")),"^",1)
        s regNo=$p(^PAPER(paitentId,"PAT",1),"^",2)
        s a.PatRegNo=regNo
    }
    if $D(tmp("Status")) s a.Status=tmp("Status")
    if $D(tmp("AuditUser")) s a.AuditUser=tmp("AuditUser")
    if $D(tmp("AuditDate")) s a.AuditDate=tmp("AuditDate")
    if $D(tmp("AuditTime")) s a.AuditTime=tmp("AuditTime")
    if $D(tmp("GetBarCode")) s a.GetBarCode=tmp("GetBarCode")
    // 原来的
#;    f i=1:1:15 {
#;        s itm="Item"_i  
#;        if $D(tmp(itm)) s $ZOBJPROPERTY(a,itm)=tmp(itm)
#;    }
    //处理 parrJson 对象
    //"{""5||11"":""jxjxjxjjx"",""5||10"":""hshshh"",""5||2"":""22"",""5||1"":""36.5"",""5||4"":""44"",""5||3"":""33"",""5||6"":""66"",""5||5"":""55"",""5||8"":""有"",""5||7"":""45"",""5||9"":""皮疹^寒战^胸闷""}
    i $g(parrJson)'="" {
        s itemType=""
        s set=##class(Nur.MNISV3.Common.JSON).Decode(parrJson)
        s key=set.Next("")
        while (key'="") {
            s value=set.GetAt(key)
            i key["||" { //分隔字符 第一个是类型
                s itemType=$p(key,"||",1)
                s itemIndex=$p(key,"||",2)
                s itm="Item"_itemIndex  
                if $g(value)'="" s $ZOBJPROPERTY(a,itm)=value
            }
            s key=set.Next(key)
           
        }
        i itemType'="" s $ZOBJPROPERTY(a,"ItemType")=itemType
    }
 
    s sc=a.%Save()
    s id=a.%Id()
    d a.%Close()
    q:$$$ISERR(sc) "err:"_$SYSTEM.Status.GetErrorText(sc)
    q id
}

Storage Default
{
<Data name="BloodBagSubRecDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>RecDate</Value>
</Value>
<Value name="3">
<Value>RecTime</Value>
</Value>
<Value name="4">
<Value>RecUser</Value>
</Value>
<Value name="5">
<Value>AuditDate</Value>
</Value>
<Value name="6">
<Value>AuditTime</Value>
</Value>
<Value name="7">
<Value>AuditUser</Value>
</Value>
<Value name="8">
<Value>Status</Value>
</Value>
<Value name="9">
<Value>EpisodeId</Value>
</Value>
<Value name="10">
<Value>PatRegNo</Value>
</Value>
<Value name="11">
<Value>LocId</Value>
</Value>
<Value name="12">
<Value>GetBarCode</Value>
</Value>
<Value name="13">
<Value>UpdateDate</Value>
</Value>
<Value name="14">
<Value>UpdateTime</Value>
</Value>
<Value name="15">
<Value>UpdateUser</Value>
</Value>
<Value name="16">
<Value>Item1</Value>
</Value>
<Value name="17">
<Value>Item2</Value>
</Value>
<Value name="18">
<Value>Item3</Value>
</Value>
<Value name="19">
<Value>Item4</Value>
</Value>
<Value name="20">
<Value>Item5</Value>
</Value>
<Value name="21">
<Value>Item6</Value>
</Value>
<Value name="22">
<Value>Item7</Value>
</Value>
<Value name="23">
<Value>Item8</Value>
</Value>
<Value name="24">
<Value>Item9</Value>
</Value>
<Value name="25">
<Value>Item10</Value>
</Value>
<Value name="26">
<Value>Item11</Value>
</Value>
<Value name="27">
<Value>Item12</Value>
</Value>
<Value name="28">
<Value>Item13</Value>
</Value>
<Value name="29">
<Value>Item14</Value>
</Value>
<Value name="30">
<Value>Item15</Value>
</Value>
<Value name="31">
<Value>ItemType</Value>
</Value>
<Value name="32">
<Value>Item16</Value>
</Value>
<Value name="33">
<Value>Item17</Value>
</Value>
<Value name="34">
<Value>Item18</Value>
</Value>
<Value name="35">
<Value>Item19</Value>
</Value>
<Value name="36">
<Value>Item20</Value>
</Value>
</Data>
<DataLocation>^Nur.MNISV3.BloodBagSubRecD</DataLocation>
<DefaultData>BloodBagSubRecDefaultData</DefaultData>
<IdLocation>{%%PARENT}("ChildSub")</IdLocation>
<IndexLocation>^Nur.MNISV3.BloodBagSubRecI</IndexLocation>
<StreamLocation>^Nur.MNISV3.BloodBagSubRecS</StreamLocation>
<Type>%Storage.Persistent</Type>
}

}
